package com.google.code.stalkernet.peer.event;

import java.util.EventObject;

import com.google.code.stalkernet.message.Message;

/**
 * Encapsulates details about peer-related event.
 *
 * @author Mikhail Vladimrov
 */
public class PeerEvent extends EventObject
{
    private final Message message;

    /**
     * Create new peer event with given source.
     *
     * @param source event source
     */
    public PeerEvent (Object source)
    {
        super (source);

        message = null;
    }

    /**
     * Create new peer event with given source and message.
     *
     * @param source event source
     * @param message received {@link Message}
     */
    public PeerEvent (Object source, Message message)
    {
        super (source);

        this.message = message;
    }

    /**
     * Get {@link Message} of the event.
     *
     * @return {@link Message} object
     */
    public Message getMessage ()
    {
        if (message == null)
            throw new UnsupportedOperationException (
                "Message is not available");

        return message;
    }
}
